package day22.HomeworkCollections;

import java.util.ArrayList;
import java.util.Iterator;

public class ShoppingList extends ArrayList<Product> implements IShoppingList {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String THE_LIST_IS_EMPTY = "The list is empty.";
	private static final String WRONG_PRODUCT_MESSAGE = "This is not a  product.";

	@Override
	public void addItem(Product product) {
		if (product != null && product.getName() != null
				&& !product.getName().equals(null)) {
			this.add(product);
		} else {
			System.out.println(WRONG_PRODUCT_MESSAGE);
		}
	}

	@Override
	public Product get(int index) {
		return super.get(index);
	}

	@Override
	public void printList() {
		if (this.isEmpty()) {
			System.out.println(THE_LIST_IS_EMPTY);
		}

		for (Iterator<Product> it = this.iterator(); it.hasNext();) {
			Object product = it.next();
			System.out.println(product.toString());
		}

	}
	
	@Override
	public boolean remove(Object o) {
		
		if (!this.equals(o)){
			System.out.println("No such item.");
			return false;
		}
		
		return super.remove(o);
	}

}
